package com.hut.oa.model.bean;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.fasterxml.jackson.annotation.JsonIgnore;



/**
 * 目录表
 * @author 郑单单
 *
 */
@Entity
@Table(name="directory_")
public class Directory implements Serializable {
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	@Column(name="dir_id")
	private Long id;//目录id
	
	@Column(name="dir_name",nullable=false)
	private String text;//目录名称
	
	@JsonIgnore
	@ManyToOne()
	@JoinColumn(name="dir_father_id")	
	private Directory pid;//父目录
	
	@Column(name="dir_path")
	private String path;//路径
	
	@OneToMany()
	@Transient
	private List<Directory> children;
		
	@ManyToOne()
	@JsonIgnore
	@JoinColumn(name="u_id")	
	private User user;//用户id

	@OneToMany(mappedBy="dir",fetch = FetchType.EAGER)
	@JsonIgnore
	@Transient
	private List<FileManage> file;
	
	@Column(name="dir_is_delete",nullable=false)
	private Integer isDelete=0;//是否在回收站
	
	@Column(name="dir_permission")
	private String dirpermission="0";
	
	@JsonIgnore
	@ManyToMany(cascade=CascadeType.ALL,fetch = FetchType.LAZY)
	@JoinTable(name = "directory_user",
    joinColumns = {
            @JoinColumn(name = "du_directory_id")
    }, inverseJoinColumns = {
    @JoinColumn(name = "fu_user_id")
})
	private List<User> diruser;
	
	public Directory() {}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}	

	public List<FileManage> getFile() {
		return file;
	}

	public void setFile(List<FileManage> file) {
		this.file = file;
	}	

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	public Directory getPid() {
		return pid;
	}

	public void setPid(Directory pid) {
		this.pid = pid;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public String getPath() {
		return path;
	}

	public void setPath(String path) {
		this.path = path;
	}

	public List<Directory> getChildren() {
		return children;
	}

	public void setChildren(List<Directory> children) {		
		this.children = children;
	}
	
	public Integer getIsDelete() {
		return isDelete;
	}

	public void setIsDelete(Integer isDelete) {
		this.isDelete = isDelete;
	}

	public String getDirpermission() {
		return dirpermission;
	}

	public void setDirpermission(String dirpermission) {
		this.dirpermission = dirpermission;
	}

	

	public List<User> getDiruser() {
		return diruser;
	}

	public void setDiruser(List<User> diruser) {
		this.diruser = diruser;
	}

	@Override
	public String toString() {
		return "Directory [id=" + id + ", text=" + text + ", pid=" + pid + "]";
	}	
}
